package com.duck.base.oauth.security.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.duck.base.oauth.security.model.HandlerModel;
import com.duck.base.response.BaseResponse;

/**
 * 未授权返回json
 * @author lwy
 *
 */
@Component
public class DuckAccessDeniedHandler implements AccessDeniedHandler {

	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response,
			AccessDeniedException accessDeniedException) throws IOException, ServletException {
		// TODO Auto-generated method stub
		BaseResponse<HandlerModel> baseResp = new BaseResponse<HandlerModel>();
		baseResp.setStatus("401");
		baseResp.setMessage("未认证");
		response.getWriter().write(JSON.toJSONString(baseResp));
	}

}
